package com.atguigu.tingshu.common.util;

/**
 * 获取当前用户信息帮助类
 * @author xiongkunYang
 */
public class AuthContextHolder {

    private static final ThreadLocal<Long> USER_ID = new ThreadLocal<>();
    private static final ThreadLocal<String> USERNAME = new ThreadLocal<>();
    public static final ThreadLocal<String> LOGIN_KEY = new ThreadLocal<>();

    public static void setUserId(Long userId) {
        USER_ID.set(userId);
    }

    public static Long getUserId() {
//        return 1L;
        return USER_ID.get();
    }

    public static void removeUserId() {
        USER_ID.remove();
    }

    public static void setUsername(String username) {
        USERNAME.set(username);
    }

    public static String getUsername() {
        return USERNAME.get();
    }

    public static void removeUsername() {
        USERNAME.remove();
    }

    public static void setLoginKey(String loginKey) {
        LOGIN_KEY.set(loginKey);
    }

    public static String getLoginKey() {
        return LOGIN_KEY.get();
    }

    public static void removeLoginKey() {
        LOGIN_KEY.remove();
    }

}
